﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Net;
using System.Text;
/// <summary>
/// Summary description for imgs
/// </summary>
public class files
{
    public files()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    //PHAN TA VIET CODE
    public static bool ThumbnailCallback()
    {
        return false;
    }
    public static string fnSaveImage(string sPath, System.Web.UI.HtmlControls.HtmlInputFile FileUpload, int imageWidth, int imageHeight, int DelleteImgOrigin)
    {
        try
        {
            string sImg;
            string sImgThumb;
            string SaveLocation;
            DateTime MyDate = DateTime.Now;
            String MyString = MyDate.ToString("ddMMyyhhmmss");
            Random rdn = new Random();
            String rdnString = (rdn.Next(10000)).ToString();
            while (rdnString.Length<4)
            {
                rdnString = "0" + rdnString;
            }
            MyString = MyString + rdnString;
            sImg = MyString + ".Jpeg";
            sImgThumb = MyString + "Thumb.Jpeg";

            SaveLocation = sPath + "\\" + sImg;
            if (FileUpload.PostedFile.ContentLength > 0)
            {
                FileUpload.PostedFile.SaveAs(SaveLocation);

                /*Tao anh thumb*/

                if ((imageHeight == 0) && (imageWidth == 0))
                {
                    imageHeight = 100;
                    imageWidth = 100;
                }
                    else
                {
                    Bitmap bImg = (Bitmap)Bitmap.FromStream(FileUpload.PostedFile.InputStream);
                    if (imageHeight == 0)
                    {
                        imageHeight = bImg.Height * imageWidth / bImg.Width;
                    }
                    if (imageWidth == 0)
                    {
                        imageWidth = bImg.Width * imageHeight / bImg.Height;

                    }
                }

                System.Drawing.Image fullSizeImg = System.Drawing.Image.FromFile(SaveLocation);
                System.Drawing.Image.GetThumbnailImageAbort dummyCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
                System.Drawing.Image thumbNailImg = fullSizeImg.GetThumbnailImage(imageWidth, imageHeight, dummyCallBack, IntPtr.Zero);

                SaveLocation = sPath + "\\" + sImgThumb;
                thumbNailImg.Save(SaveLocation, ImageFormat.Jpeg);
                thumbNailImg.Dispose();
                fullSizeImg.Dispose();

                // Xoa anh goc
                if (DelleteImgOrigin == 1)
                {
                    SaveLocation = sPath + "\\" + sImg;
                    if (File.Exists(SaveLocation))
                    {
                        File.Delete(SaveLocation);
                        //File.Delete("c:\\inetpub\\wwwroot\\uploads\\2109070531292082Thumb.Jpeg");
                    }
                }


            }
            else
            {
                sImg = "";
            }
            /*Het cap nhat anh*/
            return sImg;
        }
        catch (Exception ex)
        {
            return "";
            //return ex.ToString();
        }
    }

    public static string fnSaveImageProduct(string sPath, System.Web.UI.HtmlControls.HtmlInputFile FileUpload, int DelleteImgOrigin)
    {
        try
        {
            //Khai bao bien toa do
            int x, y, w, h, imageWidth, imageHeight, imageHeightOrigin, imageWidthOrigin;
            //Ten anh ngau nhien va theo thoi gian
            string sImgOrigin;
            string sImg;
            string sImgThumb;
            string SaveLocation;

            if (FileUpload.PostedFile.ContentLength > 0)
            {
                /*Cap nhat anh*/
    	        //Tao ten anh ngau nhien va theo thoi gian
                
    	        sImgOrigin = System.IO.Path.GetFileName(FileUpload.PostedFile.FileName);

                DateTime MyDate = DateTime.Now;
                String MyString = MyDate.ToString("ddMMyyhhmmss");
                Random rdn = new Random();
                String rdnString = (rdn.Next(10000)).ToString();
                while (rdnString.Length < 4)
                {
                    rdnString = "0" + rdnString;
                }
                MyString = MyString + rdnString;

                

                sImg = MyString + ".Jpeg";
                sImgThumb = MyString + "Thumb.Jpeg";

                        
    		    /*Tao anh san pham */
	            Bitmap bImg = (Bitmap)Bitmap.FromStream(FileUpload.PostedFile.InputStream);
                imageHeightOrigin = bImg.Height;
                imageWidthOrigin = bImg.Width;
		        /*Tao anh goc*/
	            SaveLocation = sPath + "\\" + sImgOrigin;
                FileUpload.PostedFile.SaveAs(SaveLocation);
                /*Tao anh chi tiet*/
		        imageWidth=600;
		        imageHeight=600;
		        //if (imageHeightOrigin/imageHeight>imageWidthOrigin/imageWidth)
                if (imageHeightOrigin > imageWidthOrigin)
                {
			           h=imageHeight;
                       w = imageWidthOrigin * h / imageHeightOrigin;                    
                }
                else
                {
			        w=imageWidth;
                    h = imageHeightOrigin * w / imageWidthOrigin;
                }
                imageWidth = w;
                imageHeight = h;
		        x=(imageWidth-w)/2;
		        y=(imageHeight-h)/2;
                System.Drawing.Bitmap DestImage = new System.Drawing.Bitmap(imageWidth, imageHeight);
                for (int iX = 0; iX <= DestImage.Width - 1; iX++)
                {
                    for (int iY = 0; iY <= DestImage.Height - 1; iY++)
                    {
                        DestImage.SetPixel(iX, iY, System.Drawing.Color.White);
                    }
                }
    			
                //System.Drawing.Graphics.FromImage(DestImage).DrawImage(System.Drawing.Image.FromFile(SaveLocation),x,y,w,h);
                SaveLocation = sPath + "\\" + sImgOrigin;
                System.Drawing.Image fullSizeImg = System.Drawing.Image.FromFile(SaveLocation);
                System.Drawing.Graphics.FromImage(DestImage).DrawImage(fullSizeImg, x, y, w, h);
                SaveLocation = sPath + "\\" + sImg;
	            DestImage.Save(SaveLocation, System.Drawing.Imaging.ImageFormat.Jpeg);
	            DestImage.Dispose();
                fullSizeImg.Dispose();

                /*Tao anh thumb*/
		        imageWidth=100;
		        imageHeight=100;
		        //if (imageHeightOrigin/imageHeight > imageWidthOrigin/imageWidth)
                if (imageHeightOrigin > imageWidthOrigin)
                {
			        h=imageHeight;
                    w = imageWidthOrigin * h / imageHeightOrigin;                    
                }
                    else
                {
			        w=imageWidth;
                    h = imageHeightOrigin * w / imageWidthOrigin;
                }
                x = (imageWidth - w) / 2;
                y = (imageHeight - h) / 2;
                System.Drawing.Bitmap DestImage2 = new System.Drawing.Bitmap(imageWidth, imageHeight);

                for (int iX = 0; iX <= DestImage2.Width - 1; iX++)
                {
                    for (int iY = 0; iY <= DestImage2.Height - 1; iY++)
                    {
                        DestImage2.SetPixel(iX, iY, System.Drawing.Color.White);
                    }
                }

                //System.Drawing.Graphics.FromImage(DestImage2).DrawImage(System.Drawing.Image.FromFile(SaveLocation), x, y, w, h);
                SaveLocation = sPath + "\\" + sImgOrigin;
                System.Drawing.Image fullSizeImg2 = System.Drawing.Image.FromFile(SaveLocation);
                System.Drawing.Graphics.FromImage(DestImage2).DrawImage(fullSizeImg2, x, y, w, h);
                SaveLocation = sPath + "\\" + sImgThumb;
                DestImage2.Save(SaveLocation, System.Drawing.Imaging.ImageFormat.Jpeg);
                DestImage2.Dispose();
                fullSizeImg2.Dispose();

                    // Xoa anh goc
                if (DelleteImgOrigin == 1)
                {
                    SaveLocation = sPath + "\\" + sImgOrigin;
                    if (File.Exists(SaveLocation))
                    {
                        File.Delete(SaveLocation); 
                   }
                }

            }
            else
            {
                sImg = "";
            }
            /*Het cap nhat anh*/
            return sImg;
        }
        catch (Exception ex)
        {
            //return ex.ToString();
            //throw ex;
            return "";
        }
    }

    public static string fnSaveImageAdv(string sPath, System.Web.UI.HtmlControls.HtmlInputFile FileUpload, int DelleteImgOrigin)
    {
        try
        {
            //Khai bao bien toa do
            int x, y, w, h, imageWidth, imageHeight, imageHeightOrigin, imageWidthOrigin;
            //Ten anh ngau nhien va theo thoi gian
            string sImgOrigin;
            string sImg;
            string sImgThumb;
            string SaveLocation;
            string sYear = comm.GetCurrentYear();
            string sMonth = comm.GetCurrentMonth();
            string sDay = comm.GetCurrentDay();
            string sHour = comm.GetCurrentHour();
            string sMinute = comm.GetCurrentMinute();

            string s = "\\" + sYear + "\\" + sMonth + "\\" + sDay;
            sPath = sPath + s;


            if (FileUpload.PostedFile.ContentLength > 0)
            {
                /*Cap nhat anh*/
                //Tao ten anh ngau nhien va theo thoi gian

                sImgOrigin = System.IO.Path.GetFileName(FileUpload.PostedFile.FileName);
                
                String MyString = Guid.NewGuid().ToString();
                sImg = MyString + ".Jpeg";
                sImgThumb = MyString + "Thumb.Jpeg";

                


                if (!Directory.Exists(sPath))
                {
                    Directory.CreateDirectory(sPath);
                }

                /*Tao anh san pham */
                Bitmap bImg = (Bitmap)Bitmap.FromStream(FileUpload.PostedFile.InputStream);
                imageHeightOrigin = bImg.Height;
                imageWidthOrigin = bImg.Width;
                /*Tao anh goc*/
                SaveLocation = sPath + "\\" + sImgOrigin;
                FileUpload.PostedFile.SaveAs(SaveLocation);
                /*Tao anh chi tiet*/
                imageWidth = 600;
                imageHeight = 600;
                //if (imageHeightOrigin/imageHeight>imageWidthOrigin/imageWidth)
                if (imageHeightOrigin > imageWidthOrigin)
                {
                    h = imageHeight;
                    w = imageWidthOrigin * h / imageHeightOrigin;
                }
                else
                {
                    w = imageWidth;
                    h = imageHeightOrigin * w / imageWidthOrigin;
                }
                imageWidth = w;
                imageHeight = h;
                x = (imageWidth - w) / 2;
                y = (imageHeight - h) / 2;
                System.Drawing.Bitmap DestImage = new System.Drawing.Bitmap(imageWidth, imageHeight);
                for (int iX = 0; iX <= DestImage.Width - 1; iX++)
                {
                    for (int iY = 0; iY <= DestImage.Height - 1; iY++)
                    {
                        DestImage.SetPixel(iX, iY, System.Drawing.Color.White);
                    }
                }

                //System.Drawing.Graphics.FromImage(DestImage).DrawImage(System.Drawing.Image.FromFile(SaveLocation),x,y,w,h);
                SaveLocation = sPath + "\\" + sImgOrigin;
                System.Drawing.Image fullSizeImg = System.Drawing.Image.FromFile(SaveLocation);
                System.Drawing.Graphics.FromImage(DestImage).DrawImage(fullSizeImg, x, y, w, h);
                SaveLocation = sPath + "\\" + sImg;
                DestImage.Save(SaveLocation, System.Drawing.Imaging.ImageFormat.Jpeg);
                DestImage.Dispose();
                fullSizeImg.Dispose();

                /*Tao anh thumb*/
                imageWidth = 100;
                imageHeight = 100;
                //if (imageHeightOrigin/imageHeight > imageWidthOrigin/imageWidth)
                if (imageHeightOrigin > imageWidthOrigin)
                {
                    h = imageHeight;
                    w = imageWidthOrigin * h / imageHeightOrigin;
                }
                else
                {
                    w = imageWidth;
                    h = imageHeightOrigin * w / imageWidthOrigin;
                }
                x = (imageWidth - w) / 2;
                y = (imageHeight - h) / 2;
                System.Drawing.Bitmap DestImage2 = new System.Drawing.Bitmap(imageWidth, imageHeight);

                for (int iX = 0; iX <= DestImage2.Width - 1; iX++)
                {
                    for (int iY = 0; iY <= DestImage2.Height - 1; iY++)
                    {
                        DestImage2.SetPixel(iX, iY, System.Drawing.Color.White);
                    }
                }

                //System.Drawing.Graphics.FromImage(DestImage2).DrawImage(System.Drawing.Image.FromFile(SaveLocation), x, y, w, h);
                SaveLocation = sPath + "\\" + sImgOrigin;
                System.Drawing.Image fullSizeImg2 = System.Drawing.Image.FromFile(SaveLocation);
                System.Drawing.Graphics.FromImage(DestImage2).DrawImage(fullSizeImg2, x, y, w, h);
                SaveLocation = sPath + "\\" + sImgThumb;
                DestImage2.Save(SaveLocation, System.Drawing.Imaging.ImageFormat.Jpeg);
                DestImage2.Dispose();
                fullSizeImg2.Dispose();

                // Xoa anh goc
                if (DelleteImgOrigin == 1)
                {
                    SaveLocation = sPath + "\\" + sImgOrigin;
                    if (File.Exists(SaveLocation))
                    {
                        File.Delete(SaveLocation);
                    }
                }


                sImg = s + "\\" + sImg;
                sImg = sImg.Replace("\\", "/");
            }
            else
            {
                sImg = "";
            }
            /*Het cap nhat anh*/
            return sImg;
        }
        catch (Exception ex)
        {
            //return ex.ToString();
            //throw ex;
            return "";
        }
    }

    //---------------------------------------
    public static string fnUploadPhotos(string sPath, System.Web.UI.HtmlControls.HtmlInputFile FileUpload)
    {
        try
        {
            if (checdataX(FileUpload))
            {
                //Khai bao bien toa do
                int x, y, w, h, imageWidth, imageHeight, imageHeightOrigin, imageWidthOrigin;
                string sImgOrigin;
                string sImg ="";
                string SaveLocation;
                string sYear = comm.GetCurrentYear();
                string sMonth = comm.GetCurrentMonth();
                string sDay = comm.GetCurrentDay();

                string s = "\\" + sYear + "\\" + sMonth + "\\" + sDay;
                sPath = sPath + s;


                if (FileUpload.PostedFile.ContentLength > 0)
                {
                    /*Cap nhat anh*/
                    sImgOrigin = System.IO.Path.GetFileName(FileUpload.PostedFile.FileName);

                    String MyString = Guid.NewGuid().ToString();
                    MyString = MyString + ".Jpeg";

                    if (!Directory.Exists(sPath))
                    {
                        Directory.CreateDirectory(sPath);
                    }

                    /*Tao anh san pham */
                    Bitmap bImg = (Bitmap)Bitmap.FromStream(FileUpload.PostedFile.InputStream);
                    imageHeightOrigin = bImg.Height;
                    imageWidthOrigin = bImg.Width;
                    /*Tao anh goc*/
                    SaveLocation = sPath + "\\" + MyString;
                    FileUpload.PostedFile.SaveAs(SaveLocation);
                    /*Tao anh chi tiet*/
                    imageWidth = 400;
                    imageHeight = 400;
                    //if (imageHeightOrigin/imageHeight>imageWidthOrigin/imageWidth)
                    if (imageHeightOrigin > imageWidthOrigin)
                    {
                        h = imageHeight;
                        w = imageWidthOrigin * h / imageHeightOrigin;
                    }
                    else
                    {
                        w = imageWidth;
                        h = imageHeightOrigin * w / imageWidthOrigin;
                    }

                    imageWidth = w;
                    imageHeight = h;
                    x = (imageWidth - w) / 2;
                    y = (imageHeight - h) / 2;
                    System.Drawing.Bitmap DestImage = new System.Drawing.Bitmap(imageWidth, imageHeight);
                    for (int iX = 0; iX <= DestImage.Width - 1; iX++)
                    {
                        for (int iY = 0; iY <= DestImage.Height - 1; iY++)
                        {
                            DestImage.SetPixel(iX, iY, System.Drawing.Color.White);
                        }
                    }

                    //System.Drawing.Graphics.FromImage(DestImage).DrawImage(System.Drawing.Image.FromFile(SaveLocation),x,y,w,h);
                    SaveLocation = sPath + "\\" + MyString;
                    System.Drawing.Image fullSizeImg = System.Drawing.Image.FromFile(SaveLocation);
                    System.Drawing.Graphics.FromImage(DestImage).DrawImage(fullSizeImg, x, y, w, h);
                    SaveLocation = sPath + "\\" + sImgOrigin;
                    

                    DestImage.Save(SaveLocation, System.Drawing.Imaging.ImageFormat.Jpeg);
                    DestImage.Dispose();
                    fullSizeImg.Dispose();

                    string sd = "";
                    sd = sPath + "\\" + MyString;
                    if (File.Exists(sd))
                    {
                        File.Delete(sd);
                    }


                    sImg = s + "\\";
                    sImg = sImg.Replace("\\", "/");
                }
                else
                {
                    sImg = "";
                }
                /*Het cap nhat anh*/
                return sImg;
            }
            else
                return "";
        }
        catch (Exception ex)
        {
            //return ex.ToString();
            //throw ex;
            return "";
        }    
    
    }

    public static bool checdataX(System.Web.UI.HtmlControls.HtmlInputFile FileUpload)
    {
        string fileName = "";

        fileName = System.IO.Path.GetFileName(FileUpload.PostedFile.FileName);
        if (FileUpload.PostedFile.ContentLength > 0)
        {
            // Get the size in bytes of the file to upload.
            int fileSize = FileUpload.PostedFile.ContentLength;

            // Allow only files less than _fileSize bytes and have extension is .jpg to be uploaded.
            if ((fileSize < 5000 * 1024))
            {
                // Get the extension of the uploaded file.
                string extension = System.IO.Path.GetExtension(fileName);

                // Get the type  of the uploaded file.
                string fileContent = FileUpload.PostedFile.ContentType.ToString().ToLower();

                if (extension.ToLower() == ".jpg" || extension.ToLower() == ".png" || extension.ToLower() == ".gif" || extension.ToLower() == ".jpeg")
                {
                    if (fileContent == "image/jpeg" || fileContent == "image/png" || fileContent == "image/jpg" || fileContent == "image/gif")
                    {
                        
                        return true;

                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;

                }
            }
            else
            {
                return false;

            }
        }

        return false;
    
    }

    //---------luu anh vao thu muc file-----------------


    public static string fnSavePhotos(string sPath, System.Web.UI.HtmlControls.HtmlInputFile FileUpload)
    {
        string sYear = comm.GetCurrentYear();
        string sMonth = comm.GetCurrentMonth();
        string sDay = comm.GetCurrentDay();
        string fileName = "";

        fileName = System.IO.Path.GetFileName(FileUpload.PostedFile.FileName);
        string s =  "\\" + sYear + "\\" + sMonth + "\\" + sDay;
        sPath = sPath + s;

        string SaveLocation = sPath + "\\" + fileName;
        if (FileUpload.PostedFile.ContentLength > 0)
        {
            // Get the size in bytes of the file to upload.
            int fileSize = FileUpload.PostedFile.ContentLength;

            // Allow only files less than _fileSize bytes and have extension is .jpg to be uploaded.
            if ((fileSize < 5000 * 1024))
            {
                // Get the extension of the uploaded file.
                string extension = System.IO.Path.GetExtension(fileName);

                // Get the type  of the uploaded file.
                string fileContent = FileUpload.PostedFile.ContentType.ToString().ToLower();

                if (extension.ToLower() == ".jpg" || extension.ToLower() == ".png" || extension.ToLower() == ".gif" || extension.ToLower() == ".jpeg")
                {
                    if (fileContent == "image/jpeg" || fileContent == "image/png" || fileContent == "image/jpg" || fileContent == "image/gif")
                    {
                        if (!Directory.Exists(sPath))
                        {
                            Directory.CreateDirectory(sPath);
                        }
                        FileUpload.PostedFile.SaveAs(SaveLocation);

                        return s = s.Replace("\\", "/");
                        
                    }
                    else
                    {
                        return "";
                    }
                }
                else
                {
                   return "";
                    
                }
            }
            else
            {
                return "";
               
            }
        }

        return "";
        
    }


    //------------het phan luu file----------------------


    //---------luu file Zip vao thu muc file-----------------

    public static string fnSavefileZip(string sPath, System.Web.UI.HtmlControls.HtmlInputFile FileUpload)
    {
        string sYear = comm.GetCurrentYear();
        string sMonth = comm.GetCurrentMonth();
        string sDay = comm.GetCurrentDay();
        string fileName = "";

        fileName = System.IO.Path.GetFileName(FileUpload.PostedFile.FileName);
        string s = "\\" + sYear + "\\" + sMonth + "\\" + sDay;
        sPath = sPath + s;

        string SaveLocation = sPath + "\\" + fileName;
        if (FileUpload.PostedFile.ContentLength > 0)
        {
            // Get the size in bytes of the file to upload.
            int fileSize = FileUpload.PostedFile.ContentLength;

            // Allow only files less than _fileSize bytes and have extension is .jpg to be uploaded.
            if ((fileSize < 5000 * 1024))
            {
                // Get the extension of the uploaded file.
                string extension = System.IO.Path.GetExtension(fileName);

                // Get the type  of the uploaded file.
                string fileContent = FileUpload.PostedFile.ContentType.ToString().ToLower();

                if (extension.ToLower() == ".zip" )
                {
                    if (fileContent == "application/octet-stream" || fileContent == "application/x-zip-compressed")
                    {
                        if (!Directory.Exists(sPath))
                        {
                            Directory.CreateDirectory(sPath);
                        }
                        FileUpload.PostedFile.SaveAs(SaveLocation);

                        return s = s.Replace("\\", "/");

                    }
                    else
                    {
                        return "";
                    }
                }
                else
                {
                    return "";

                }
            }
            else
            {
                return "";

            }
        }

        return "";

    }


    //------------het phan luu file Zip----------------------
    public static string fnImageNameThumb(object oInput)
    {
        string sInput, sOutput;

        if (oInput == null)
        {
            sInput = "";
        }
        else
        {
            sInput = oInput.ToString().Trim();
        }
        if (sInput == "")
        {
            sOutput = "";
        }
        else
        {
            sOutput = sInput.Replace(".Jpeg", "Thumb.Jpeg");
        }
        return sOutput;
    }
    //Ham ghi log

    public static bool writeLog(string sValue)
    {
	    try{
            //string sLog=comm.GetStrTime("yyyymmddhhmm")+": "+sValue;
            //string sFileName = "log\\" + (comm.GetStrTime("yyyymmdd")).Replace("/", "") + ".txt";
                           // srSource = File.OpenText(System.Web.HttpContext.Current.Server.MapPath("/")+"/log/log.txt");
                            //        srSource.WriteLine(sLog);
                            //srSource.Close();
            //System.IO.StreamWriter file = new System.IO.StreamWriter(System.Web.HttpContext.Current.Server.MapPath("/") + sFileName,true); 
            //file.WriteLine(sLog,true); 
            //file.Close(); 
                return true;
            }
            catch //(Exception ex)
            {
                //Console.Write("Co loi xay ra " + ex.Message);
                return false;
            }
    }
    //HET PHAN TA VIET CODE
    
    public static string fnGetImageNameThumb(object oInput)
    {
        string sInput, sOutput;

        if (oInput == null)
        {
            sInput = "";
        }
        else
        {
            sInput = oInput.ToString().Trim();
        }
        if (sInput == "")
        {
            sOutput = "";
        }
        else
        {
            sOutput = sInput.Replace(".Jpeg", "Thumb.Jpeg");
        }
        return sOutput;
    }
    public static bool fnRemoveImageThumbAndDetail(string sUrl)
    {
        try
        {
            if ((sUrl == null) || (sUrl == "")) return true;
            string sPath = sUrl;
            //Thu hien xoa qua service
            //vn.truongxua.fs1.service uploadfile = new vn.truongxua.fs1.service();
            //uploadfile.DeleteFile(sUrl);
            //DeleteFile(fnGetImageNameThumb(sUrl));
           
            //Thu hien xoa tai server
            string sDomainName = comm.getDomainName();
            sPath = sPath.Replace(sDomainName, comm.getPathRoot());
            sPath = sPath.Replace("/", "\\");

            //Delete detail
            if (File.Exists(sPath))
            {
                File.Delete(sPath);
            }

            //Delete thumb
            sPath = fnGetImageNameThumb(sPath);
            if (File.Exists(sPath))
            {
                File.Delete(sPath);
            }
            return true;
        }
        catch //(Exception ex)
        {
            //Console.Write("Co loi xay ra " + ex.Message);
            return false;
            //throw ex;
        }
    }
}
